import requests

import json

from maltego_trx.entities import Domain

from maltego_trx.transform import DiscoverableTransform


class fofaip(DiscoverableTransform):
    """
    Receive DNS name from the client, and resolve to IP address.
    """

    @classmethod
    def create_entities(cls, request, response):
        ip = request.Value
        # print(type(ip))
        # print(ip)

        re2 = requests.get("http://192.168.2.128/test/" + ip)

        # print(re2.text)

        jre2 = json.loads(re2.text)
        # print(jre2, type(jre2))

        # print(type(jre2["urls"]))
        i = 0  # i是下标
        while i < len(jre2["urls"]):
            # print(jre2["urls"][i])
            url = jre2["urls"][i]
            i += 1
            response.addEntity(Domain, url)
